<?php
namespace App\Models;

class DaredoMo extends Base {

    public function initialize() {
        parent::initialize();
    }

    public function isExists($mobile) {
        $query = 'SELECT COUNT(*) AS `cnt` FROM `nc` WHERE mobile=:mobile';
        try {
            $ret = $this->db()->query($query, ['mobile' => $mobile])->fetch();
            if($ret != false) {
                if(is_array($ret) && count($ret) > 0 && isset($ret['cnt'])) {
                    return $ret['cnt'] > 0;
                }
            }
        } catch(\PDOException $ex) {
            $this->errorLog('SELECT', $query->getPhql(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

    public function add($entity) {
        try {
            if($this->db()->insertAsDict('daredo_mo_log', $entity)) {
                return $this->db()->lastInsertId();
            }
        } catch(\PDOException $ex) {
            $this->errorLog('INSERT', $this->db()->getSQLStatement(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }
}
